package main.database;

import com.mongodb.client.MongoCollection;
import main.GlobalConfig;
import org.bson.Document;

public class StatisticHelper {
    public static String KeyOfRankPage = "RankPage";
    public static String KeyOfMainPage = "MainPage";
    public static String KeyOfArticlePage = "ArticlePage";
    public static String KeyOfAuthorPage = "AuthorPage";
    public static String KeyOfTopPage = "TopPage";

    public static void addRankPageAccess(String user, String ip, String time, String userAgent) {
        MongoCollection<Document> collection = DatabaseMan.Instance().GetCollection(GlobalConfig.collectionNameOfStatistic);
        Document document = new Document("key", KeyOfRankPage)
                .append("user", user)
                .append("ip", ip)
                .append("time", time)
                .append("agent", userAgent);

        collection.insertOne(document);
    }

    public static void addMainPageAccess(String user, String ip, String time, String userAgent) {
        MongoCollection<Document> collection = DatabaseMan.Instance().GetCollection(GlobalConfig.collectionNameOfStatistic);
        Document document = new Document("key", KeyOfMainPage)
                .append("user", user)
                .append("ip", ip)
                .append("time", time)
                .append("agent", userAgent);

        collection.insertOne(document);
    }

    public static void addArticlePageAccess(String user, String ip, String time, String userAgent) {
        MongoCollection<Document> collection = DatabaseMan.Instance().GetCollection(GlobalConfig.collectionNameOfStatistic);
        Document document = new Document("key", KeyOfArticlePage)
                .append("user", user)
                .append("ip", ip)
                .append("time", time)
                .append("agent", userAgent);

        collection.insertOne(document);
    }

    public static void addAuthorPageAccess(String user, String ip, String time, String userAgent) {
        MongoCollection<Document> collection = DatabaseMan.Instance().GetCollection(GlobalConfig.collectionNameOfStatistic);
        Document document = new Document("key", KeyOfAuthorPage)
                .append("user", user)
                .append("ip", ip)
                .append("time",time)
                .append("agent", userAgent);

        collection.insertOne(document);
    }

    public static void addTopPageAccess(String user, String ip, String time, String userAgent) {
        MongoCollection<Document> collection = DatabaseMan.Instance().GetCollection(GlobalConfig.collectionNameOfStatistic);
        Document document = new Document("key", KeyOfTopPage)
                .append("user", user)
                .append("ip", ip)
                .append("time", time)
                .append("agent", userAgent);

        collection.insertOne(document);
    }
}
